package com.cma.cmabackend.controller;

import com.cma.cmabackend.entity.Project;
import com.cma.cmabackend.entity.in.InProject;
import com.cma.cmabackend.entity.re.ReDetailProject;
import com.cma.cmabackend.entity.re.ReProject;
import com.cma.cmabackend.service.ProjectService;
import jakarta.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/project")
public class ProjectController {
    @Resource
    ProjectService projectService;

    @Transactional
    @PostMapping("")
    public Project addProject(@RequestBody InProject inProject) {
        return projectService.addProject(inProject.getName(), inProject.getReason(), inProject.getCreater_id(), inProject.getStandard());
    }

    @GetMapping("/progressing-completed")
    public List<ReProject> getAllProgressingAndCompleted() {
        return projectService.getAllProgressingAndCompleted();
    }

    @GetMapping("/confirming")
    public List<ReProject> getAllConfirming() {
        return projectService.getAllConfirming();
    }

    @GetMapping("/confirming-confirmed-agreed")
    public List<ReProject> getAllConfirmingAndConfirmedAndAgreed() {
        return projectService.getAllConfirmingAndConfirmedAndAgreed();
    }

    @GetMapping("/confirmed-agreed")
    public List<ReProject> getAllConfirmedAndAgreed() {
        return projectService.getAllConfirmedAndAgreed();
    }

    @GetMapping("/get")
    public ReDetailProject getProject(int id) {
        return projectService.findById(id);
    }

    @GetMapping("/to-quality")
    public void toQuality(Integer id) {
        projectService.setStatus(id, Project.Status.Confirming);
    }

    @GetMapping("/to-confirm")
    public void confirm(Integer id) {
        projectService.setStatus(id, Project.Status.Confirmed);
    }

    @GetMapping("/to-completed")
    public void toCompleted(Integer id) {
        projectService.setStatus(id, Project.Status.Completed);
    }

    @GetMapping("/to-agreed")
    public void toAgreed(Integer id) {
        projectService.setStatus(id, Project.Status.Agreed);
    }
}
